"""
初始化 | 数据库索引
"""

from typing import Iterator


def init_db_index() -> None:
    """ 初始化 | 数据库索引 """

    import inspect

    import service
    from components.logger import log
    from service.base import ServiceBase

    # 获取所有 Service 类（ServiceBase 的子类）
    service_classes: Iterator[type[ServiceBase]] = (
        obj
        for name, obj in inspect.getmembers(service)
        if (
            inspect.isclass(obj)
            and issubclass(obj, ServiceBase)
            and obj != ServiceBase
        )
    )

    # 初始化索引
    for service_class in service_classes:
        service_class.init_index()
        log.success(f"[MongoDB][索引] 初始化 {service_class.__name__}")
